package handlerChain;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

public class HandlerChain {

    @Resource
    private AHandler aHandler;

    @Resource
    private BHandler bHandler;

    @Resource
    private CHandler cHandler;

    private List<BaseFilterHandler> chainFilter = new ArrayList<>();


    @PostConstruct
    public void init(){
        aHandler = new AHandler();
        bHandler = new BHandler();
        cHandler = new CHandler();
        chainFilter.add(aHandler);
        chainFilter.add(bHandler);
        chainFilter.add(cHandler);
    }

    public void execChailFilter(SerialOrder object){
        aHandler = new AHandler();
        bHandler = new BHandler();
        cHandler = new CHandler();
        chainFilter.add(aHandler);
        chainFilter.add(bHandler);
        chainFilter.add(cHandler);
        for(BaseFilterHandler handler : chainFilter){
            if(!handler.isHandler(object.getStatus())){
                continue;
            }
            if(handler.handle(object)){
                //break;
                continue;
            }
        }

    }










}
